/* 
File     : Server.java
Function : Starts RMI registry, Instanciates and exports Remote Object
Author   : Kunal Cholera

*/
import java.rmi.*;
import java.rmi.server.*;

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;

import java.net.*;
import java.io.*;


public class Server{

  private static void startRegistry( int registryPortNumber ) throws RemoteException{
    try{
	 	  Registry registry = LocateRegistry.getRegistry( registryPortNumber );
	  	  registry.list();

	   }catch( Exception e ){

   		  System.out.println( "Creating new Registry");
		  Registry registry = LocateRegistry.createRegistry( registryPortNumber );

	   }//end catch
  }//end startRegistry

  private static void exportObject( int registryPortNumber ){
	String registryURL;

	try{
   		  Processor myProcessorObject = new Processor();
		  registryURL = "rmi://localhost:"+ registryPortNumber + "/processor";
		  Naming.rebind( registryURL, myProcessorObject );
		  System.out.println("processor object exported");

	}catch( Exception er ){ System.out.println(" Error in exportObject() :" +er ); }	
	
	
  }//end exportObjects()

  public static void main( String args[] )
  {
    int registryPortNumber = 2000;
  
    try{
		  startRegistry( registryPortNumber );
		  exportObject( registryPortNumber );

    }catch( Exception e ){ System.out.println("Error during exporting the object"); }
  }//end main

}//end Server 
/*
Todo :


*/